package com.my.spring.readcode.demo;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 王存露
 * @version 1.0.0
 * @date 2021/2/1 11:38
 */
@Slf4j
public class MyMonitorThread implements Runnable {
    private UserRepository userRepository;
    private RandomNameUtils utils;

    public MyMonitorThread(UserRepository userRepository, RandomNameUtils utils) {
        this.userRepository = userRepository;
        this.utils = utils;
    }


    @Override
    public void run() {
        String[] strings = new String[]{"man", "woman"};
        User build = User.builder().build();
        build.setAge(RandomUtil.randomNumbers(2));
        build.setUsername(utils.getRandomName());
        build.setUserCd(RandomUtil.randomNumbers(16));
        build.setPassword(SecureUtil.md5(RandomUtil.randomNumbers(12121)));
        DateTime dateTime = RandomUtil.randomDay(0, 200);
        build.setCreateTime(dateTime);
        build.setSex(strings[RandomUtil.randomInt(0, 2)]);
        log.info("insert into {}", build.toString());
        userRepository.save(build);
    }
}
